//
//(C) Copyright 2011 HongKong Airline.,Ltd. 
//
/**
 * commodityAction
 * 项目名称:代购系统
 * @author Mengxiangliang
 * 功能描述:
 * 历史版本:2013-01-04 v1.0.0 Mengxiangliang  创建:
 * @version [V1] 
 */
package com.gamutsoft.amb.commodity.action;

import java.util.List;
import java.util.Map;

import com.gamutsoft.amb.base.action.BaseAction;
import com.gamutsoft.amb.commodity.model.Commodity;
import com.gamutsoft.amb.commodity.service.ICommodityService;
import com.gamutsoft.amb.common.bean.QueryExample;
import com.gamutsoft.amb.common.exception.BusinessException;
import com.gamutsoft.amb.common.util.ConditionUtil;
import com.gamutsoft.amb.common.util.PageUtil;


@SuppressWarnings({"serial","rawtypes"})
public class CommodityAction extends BaseAction {
	
	private Commodity commodity;
	
	private List<Map> commodityList;
	
	private ICommodityService commodityService;

	/**
	 * 初始化查询Commodity信息
	 * @author Mengxiangliang
	 * @return
	 */
	public String initSearchCommodity()throws BusinessException, Exception {
		try {
		    QueryExample qe =ConditionUtil.copyConditionBySql(this.getRequest());
			PageUtil  pageutil =new PageUtil(this.getRequest());
			pageutil.setPageSize(PageUtil.PAGESIZE);
			qe.setPageUtil(pageutil);
			commodityList = commodityService.searchCommodityList(qe);
		
		} catch(BusinessException be){
			log.error(be);
			throw be;
		}catch(Exception e){
			log.error(e);
			throw e;
		}
		return "init_search_commodity_success";
	}
	
	/**
	 * 查询Commodity信息
	 * @author Mengxiangliang
	 * @return
	 */
	public String searchCommodity() throws BusinessException, Exception{
		try {
			QueryExample qe =ConditionUtil.copyConditionBySql(this.getRequest());
			PageUtil  pageutil =new PageUtil(this.getRequest());
			pageutil.setPageSize(PageUtil.PAGESIZE);
			qe.setPageUtil(pageutil);
		    commodityList = commodityService.searchCommodityList(qe);
		}catch(BusinessException be){
			log.error(be);
			throw be;
		}catch(Exception e){
			log.error(e);
			throw e;
		}
		return "search_commodity_success";
	}
	
	/**
	 * 初始化新增Commodity信息
	 * @author Mengxiangliang 
	 * @return
	 */
	public String initAddCommodity() throws BusinessException, Exception {
		if (commodity != null && commodity . getId() != null && !"".equals(commodity.getId())) {
			try {
				 commodity = commodityService.searchCommodityById(commodity.getId());
			}catch (BusinessException be) {
				log.error(be);
				throw be;
			  } catch (Exception e) {
				log.error(e);
				throw e;
			  }
	   }	  
		return "init_add_commodity_success";
	}
	
	
	
	
	
	/**
	 * 新增Commodity信息
	 * @author Mengxiangliang
	 * @return
	 */
	public String createCommodity() throws BusinessException, Exception {
		if(commodity != null) {
			try {
				commodityService . createCommodity(commodity);
			}catch(BusinessException be){
				log.error(be);
				throw be;
			}catch(Exception e){
				log.error(e);
				throw e;
			}
		}
		return "add_commodity_success";
	}
	
	/**
	 * 初始化更新Commodity信息
	 * @author Mengxiangliang 
	 * @return
	 */
	public String initUpdateCommodity()throws BusinessException, Exception{
		if (commodity != null && commodity . getId() != null && !"".equals(commodity . getId())) {
			try {
				commodity = commodityService . searchCommodityById(commodity.getId());
			} catch(BusinessException be){
				log.error(be);
				throw be;
			}catch(Exception e){
				log.error(e);
				throw e;
			}
		}
		return "init_update_commodity_success";
	}
	
	/**
	 * 更新Commodity信息
	 * @author Mengxiangliang
	 * @return
	 */
	public String updateCommodity() throws BusinessException, Exception{
		if(commodity != null && commodity . getId() != null) {
			try {
				commodityService . updateCommodity(commodity);
			} catch(BusinessException be){
				log.error(be);
				throw be;
			}catch(Exception e){
				log.error(e);
				throw e;
			}
		}
		return "update_commodity_success";
	}
	
	/**
	 * 查看Commodity信息
	 * @author Mengxiangliang 
	 * @return
	 */
	public String viewCommodity() throws BusinessException, Exception{
		if (commodity != null && commodity . getId() != null && !"".equals(commodity . getId())) {
			try {
				commodity = commodityService.searchCommodityById(commodity.getId());
			} catch(BusinessException be){
				log.error(be);
				throw be;
			}catch(Exception e){
				log.error(e);
				throw e;
			}
		}
		return "view_commodity_success";
	}
	
	/**
	 * 删除Commodity
	 * @author Mengxiangliang
	 * @return
	 */
	public String deleteCommodity() throws BusinessException, Exception{
		if (commodity != null && commodity . getId() != null && !"".equals(commodity . getId())) {
			try {
				commodityService . deleteCommodityById(commodity.getId());
			} catch(BusinessException be){
				log.error(be);
				throw be;
			}catch(Exception e){
				log.error(e);
				throw e;
			}
		}
		return "delete_commodity_success";
	}

	/**
	 * @return the commodity
	 */
	public Commodity getCommodity() {
		return commodity;
	}

	/**
	 * @param commodity the commodity to set
	 */
	public void setCommodity(Commodity commodity) {
		this.commodity = commodity;
	}

	/**
	 * @return the commodityList
	 */
	public List<Map> getCommodityList() {
		return commodityList;
	}

	/**
	 * @param commodityList the commodityList to set
	 */
	public void setCommodityList(List<Map> commodityList) {
		this.commodityList = commodityList;
	}

	/**
	 * @param commodityService the commodityService to set
	 */
	public void setCommodityService(ICommodityService commodityService) {
		this.commodityService = commodityService;
	}
}
